package com.wenshi.app.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.view.ViewStub;

import com.wenshi.view.IKeyValue;
import com.wenshi.view.WsViewTools;



/**
 * Created by Administrator on 2017/3/16.
 * 该类适用于整体Fragment刷新数据的普通布局
 */
public abstract class WsRefreshFragment extends  WsBaseFragment implements SwipeRefreshLayout.OnRefreshListener{
    private Context mContext;
    private SwipeRefreshLayout sw_downrefresh_layout;

    private boolean isNoticeSueper = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
    }


    /**
     * 将数据绑定到指定的布局的方法
     *
     *
     *
     */
    public void renderView(IKeyValue data, int layoutid) {
        setContentView(layoutid);
        super.renderView(data);

    }
    protected  void  stopRefreshing()
    {
        sw_downrefresh_layout.setRefreshing(false);
    }

    /**
     *设置自定义的视图
     *
     */
    public void setContentView(int layoutid) {
        if (!isNoticeSueper) {
            getWsWiewDelegate().setContentView(WsViewTools.getResource(mContext,"wsview_activity_pub_wsdownrefresh","layout"));

//            sw_downrefresh_layout = (SwipeRefreshLayout) findViewById(R.id.base_downrefresh_layout);
            sw_downrefresh_layout = (SwipeRefreshLayout) findViewById(WsViewTools.getResource(mContext,"base_downrefresh_layout","id"));
            sw_downrefresh_layout.setColorSchemeResources(
                    android.R.color.holo_blue_light,
                    android.R.color.holo_red_light,
                    android.R.color.holo_orange_light,
                    android.R.color.holo_green_light);
            sw_downrefresh_layout.setOnRefreshListener(this);
            isNoticeSueper = true;
        }


//        ViewStub contentview = (ViewStub) sw_downrefresh_layout.findViewById(R.id.vs_downrefresh_layout);
        ViewStub contentview = (ViewStub) sw_downrefresh_layout.findViewById(WsViewTools.getResource(mContext,"vs_downrefresh_layout","id"));
        contentview.setLayoutResource(layoutid);
        //   contentview.inflate();
        contentview.setVisibility(View.VISIBLE);

    }
}
